<html>
  <head>
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
    />
    <meta charset="UTF-8" />
    <title>test</title>
    <script src="./app.js"></script>
    <style>
      .item {
        margin: 16px;
        padding: 8px;
        border: 1px solid black;
        border-radius: 4px;
      }
    </style>
    <script>
      function testRequest() {
        app.request({
          baseUrl: "http://117.78.39.196:30888",
          url: "/ep-query/monitors",
          params: {
            days: 200,
          },
          success: (res) => {
            console.log(res);
          },
          fail: (error) => {
            console.log(error);
          },
          complete: () => {
            console.log("complete");
          },
        });
      }

      function testUploadFile() {
        const input = document.getElementById("test-file");
        console.log(input.files);

        if (input.files.length > 0) {
          var fReader = new FileReader();
          fReader.readAsDataURL(input.files[0]);
          fReader.onloadend = function (event) {
            console.log(event);
            const data = event.target.result;
            const startIndex = data.indexOf(",");

            app.request({
              baseUrl: "http://117.78.39.196:30888",
              url: "/user-center/user/file/user_group_pic",
              method: "post",
              data: {
                files: {
                  type: "image",
                  fileName: input.files[0].name,
                  data: data.slice(startIndex + 1),
                  mimeType: input.files[0].type,
                },
              },
              success: (res) => {
                console.log(res);
              },
              fail: (error) => {
                console.log(error);
              },
              complete: () => {
                console.log("complete");
              },
            });
          };
        }
      }
    </script>
  </head>

  <body>
    <div class="item" onclick="testRequest()">
      app.request(Object object)测试
    </div>
    <div class="item" onclick="testUploadFile()">
      <input type="file" accept="image/*" id="test-file" />
      <button>上传文件</button>
    </div>
  </body>
</html>
